//
//  FDMMasterCollectionReusableViewInfo.m
//  Entertainment
//
//  Created by dllo on 16/4/25.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "FDMMasterCollectionReusableViewInfo.h"

@interface FDMMasterCollectionReusableViewInfo ()

@property (nonatomic, retain) UIImageView *backGroundImage;
@property (nonatomic, retain) FDMBaseLabel *nameLabel;
@property (nonatomic, retain) FDMBaseLabel *detailLabel;
@property (nonatomic, retain) FDMBaseButton *shareButton;
@property (nonatomic, retain) FDMBaseButton *followingsButton;
@property (nonatomic, retain) FDMBaseLabel *followingsLabelData;
@property (nonatomic, retain) FDMBaseLabel *followingsLabel;
@property (nonatomic, retain) FDMBaseLabel *followLabelData;
@property (nonatomic, retain) FDMBaseLabel *followLabel;
@property (nonatomic, retain) FDMBaseLabel *favoritesData;
@property (nonatomic, retain) FDMBaseLabel *favoritesLabel;
@property (nonatomic, retain) FDMBaseButton *backButton;
@property (nonatomic, retain) FDMBaseButton *downButton;

@end
@implementation FDMMasterCollectionReusableViewInfo

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createHeaderView];
    }
    return self;
}

- (void)dealloc {
    [self.backGroundImage release];
    [self.nameLabel release];
    [self.headerImage release];
    [self.detailLabel release];
    [self.favoritesLabel release];
    [self.favoritesData release];
    [self.followLabel release];
    [self.followLabelData release];
    [self.followingsLabel release];
    [self.followingsLabelData release];
    [self.followingsButton release];
    [self.backButton release];
    [self.headerDic release];
    [super dealloc];
}

- (void)createHeaderView {
    self.backGroundImage = [[UIImageView alloc] init];
    [self addSubview:self.backGroundImage];
    [self.backGroundImage release];
    self.backButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self.backGroundImage addSubview:self.backButton];
    self.shareButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self.backGroundImage addSubview:self.shareButton];
    self.headerImage = [[UIImageView alloc] init];
    [self.backGroundImage addSubview:self.headerImage];
    [self.headerImage release];
    self.nameLabel = [[FDMBaseLabel alloc] init];
    [self.backGroundImage addSubview:self.nameLabel];
    [self.nameLabel release];
    self.detailLabel = [[FDMBaseLabel alloc] init];
    [self.backGroundImage addSubview:self.detailLabel];
    [self.detailLabel release];
    self.downButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self.backGroundImage addSubview:self.downButton];
    self.followingsButton = [FDMBaseButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:self.followingsButton];
    self.followingsLabelData = [[FDMBaseLabel alloc] init];
    [self addSubview:self.followingsLabelData];
    [self.followingsLabelData release];
    self.followingsLabel = [[FDMBaseLabel alloc] init];
    [self addSubview:self.followingsLabel];
    [self.followingsLabel release];
    self.followLabelData = [[FDMBaseLabel alloc] init];
    [self addSubview:self.followLabelData];
    [self.followLabelData release];
    self.followLabel = [[FDMBaseLabel alloc] init];
    [self addSubview:self.followLabel];
    [self.followLabel release];
    self.favoritesData = [[FDMBaseLabel alloc] init];
    [self addSubview:self.favoritesData];
    [self.favoritesData release];
    self.favoritesLabel = [[FDMBaseLabel alloc] init];
    [self addSubview:self.favoritesLabel];
    [self.favoritesLabel release];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    self.backGroundImage.userInteractionEnabled = YES;
    [self.backGroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom).with.offset(-90);
        make.right.equalTo(self.mas_right);
    }];
    
    [self.backButton setImage:[UIImage imageNamed:@"btn_back_n@2x.png"] forState:UIControlStateNormal];
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(20);
        make.left.equalTo(self.mas_left).with.offset(20);
        make.height.mas_equalTo(@40);
        make.width.mas_equalTo(@40);
    }];
    [self.backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(20);
        make.right.equalTo(self.mas_right).with.offset(-20);
        make.height.mas_equalTo(@40);
        make.width.mas_equalTo(@40);
    }];
    [self.shareButton setImage:[UIImage imageNamed:@"icon_share_n@3x.png"] forState:UIControlStateNormal];
    [self.shareButton addTarget:self action:@selector(shareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.headerImage.layer.cornerRadius = 40;
    self.headerImage.layer.masksToBounds = YES;
    self.headerImage.layer.borderWidth = 3;
    self.headerImage.layer.borderColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.00].CGColor;
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(20);
        make.left.equalTo(self.mas_left).with.offset(self.frame.size.width / 2 - 40);
        make.bottom.equalTo(self.mas_top).with.offset(100);
        make.width.mas_equalTo(@80);
        
    }];
    
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.font = [UIFont systemFontOfSize:20];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImage.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.headerImage.mas_bottom).with.offset(20);
        make.right.equalTo(self.mas_right);
        
    }];
    
    self.detailLabel.textColor = [UIColor grayColor];
    self.detailLabel.font = [UIFont systemFontOfSize:14];
    self.detailLabel.textAlignment = NSTextAlignmentCenter;
    [self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.mas_left).with.offset(self.frame.size.width / 2 - 80);
        make.width.mas_equalTo(@160);
        make.bottom.equalTo(self.nameLabel.mas_bottom).with.offset(20);
    }];
    
    [self.downButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.detailLabel.mas_bottom).with.offset(10);
        make.bottom.equalTo(self.detailLabel.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.detailLabel.mas_centerX);
        make.width.mas_equalTo(@20);
    }];
    [self.downButton setImage:[UIImage imageNamed:@"liveRadioDropDownButtonBg@2x.png"] forState:UIControlStateNormal];
    [self.downButton addTarget:self action:@selector(downButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.followingsButton setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.followingsButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.followingsButton.backgroundColor = [UIColor colorWithRed:1.00 green:0.36 blue:0.14 alpha:1.00];
    self.followingsButton.layer.cornerRadius = 5;
    self.followingsButton.layer.masksToBounds = YES;
    [self.followingsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backGroundImage.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.backGroundImage.mas_centerX);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@30);
    }];
    [self.followingsButton addTarget:self action:@selector(followingsButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.followingsLabel.textAlignment = NSTextAlignmentCenter;
    self.followingsLabel.font = [UIFont systemFontOfSize:14];
    self.followingsLabel.textColor = [UIColor grayColor];
    self.followingsLabel.text = @"关注的人";
    [self.followingsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_bottom).with.offset(-20);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.left.equalTo(self.mas_left).with.offset(30);
        make.width.mas_equalTo(@100);
    }];
    
    self.followingsLabelData.textAlignment = NSTextAlignmentCenter;
    [self.followingsLabelData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followingsButton.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.followingsLabel.mas_centerX);
        make.bottom.equalTo(self.followingsLabel.mas_top);
        make.width.mas_equalTo(@50);
    }];
    
    self.followLabel.textAlignment = NSTextAlignmentCenter;
    self.followLabel.font = [UIFont systemFontOfSize:14];
    self.followLabel.textColor = [UIColor grayColor];
    self.followLabel.text = @"粉丝";
    [self.followLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_bottom).with.offset(-20);
        make.centerX.equalTo(self.followingsButton.mas_centerX);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.width.mas_equalTo(@100);
    }];
    
    self.followLabelData.textAlignment = NSTextAlignmentCenter;
    [self.followLabelData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followingsButton.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.followLabel.mas_centerX);
        make.bottom.equalTo(self.followLabel.mas_top);
        make.width.mas_equalTo(@100);
    }];
    
    self.favoritesLabel.textAlignment = NSTextAlignmentCenter;
    self.favoritesLabel.font = [UIFont systemFontOfSize:14];
    self.favoritesLabel.textColor = [UIColor grayColor];
    self.favoritesLabel.text = @"赞过的人";
    [self.favoritesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_bottom).with.offset(-20);
        make.right.equalTo(self.mas_right).with.offset(-30);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.width.mas_equalTo(@100);
    }];
    
    self.favoritesData.textAlignment = NSTextAlignmentCenter;
    [self.favoritesData mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followingsButton.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.favoritesLabel.mas_centerX);
        make.bottom.equalTo(self.favoritesLabel.mas_top);
        make.width.mas_equalTo(@50);
    }];
    
}

- (void)setHeaderDic:(NSMutableDictionary *)headerDic {
    if (_headerDic !=headerDic) {
        [_headerDic release];
        _headerDic = [headerDic retain];
        [self.backGroundImage sd_setImageWithURL:[NSURL URLWithString:_headerDic[@"backgroundLogo"]] placeholderImage:PLACEHOLDER_IMAGE];
        self.nameLabel.text = _headerDic[@"nickname"];
        self.detailLabel.text = _headerDic[@"personalSignature"];
        self.followingsLabelData.text = [_headerDic[@"followings"] stringValue];
        [self.headerImage sd_setImageWithURL:[NSURL URLWithString:_headerDic[@"mobileMiddleLogo"]] placeholderImage:PLACEHOLDER_IMAGE];
        self.favoritesData.text = [_headerDic[@"favorites"] stringValue];
        self.followLabelData.text = [_headerDic[@"followers"] stringValue];
        
    }
}

/** 返回按钮 */
- (void)backButtonAction:(FDMBaseButton *)button {
    [self.backDelegate clickBackButton];
}

/** 分享按钮 */
- (void)shareButtonAction:(FDMBaseButton *)button {
    [self.shareDelegate clickShareButton];
}

/** 向下按钮 */
- (void)downButtonAction:(FDMBaseButton *)button {
    [self.downDelegate clickDownButton];
}

/** 关注按钮 */
- (void)followingsButtonAction:(FDMBaseButton *)button {
    [self.followingsDelegate clickFllowingsButton];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
